package cn.yuanqiao.archive.Identify.domain;

import cn.yuanqiao.common.annotation.Excel;
import cn.yuanqiao.common.core.domain.BaseEntity;
import cn.yuanqiao.common.exception.ServiceException;
import cn.yuanqiao.common.utils.StringUtils;
import cn.yuanqiao.common.utils.SecurityUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;

import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 密级
 *
 * @ProjectName: ruoyi-modules-system
 * @Package: cn.yuanqiao.archive.Identify.domain
 * @ClassName: YqMjApprove
 * @Author: lenovo
 * @Description: hbWang
 * @Date: 2023/7/26 11:52
 * @Version: 1.0
 */
public class YqMjApprove implements Serializable {
    private final String BIGTABLENAME = "_YQ_MJ_APPROVE";
    private static final long serialVersionUID = 1L;
    private String tableName;

    public YqMjApprove() {
        String tenantCode = SecurityUtils.getLoginUser().getUser().getTenantCode();
        if (StringUtils.isEmpty(tenantCode)) {
            throw new ServiceException("TenantCode is null");
        } else {
            this.tableName = tenantCode.toUpperCase() + BIGTABLENAME;
        }
    }

    /**
     * 主键id
     */
    private String id;

    /**
     * 门类id
     */
    @Excel(name = "  门类id ")
    private String categoryId;

    /**
     * 门类名称
     */
    @Excel(name = "门类名称")
    private String categoryName;

    /**
     * 菜单id
     */
    @Excel(name = "菜单id ")
    private String menuId;

    /**
     * 档案类型
     */
    @Excel(name = "档案类型")
    private String type;

    /**
     * 状态 0  审批中  1 审批结束
     */
    @Excel(name = "状态 0  审批中  1 审批结束")
    private String state;

    /**
     * 密级
     */
    @Excel(name = "密级")
    private String mjChange;


    /**
     * 密级状态
     */
    @Excel(name = "密级状态")
    private String mjType;

    /**
     * 创建者
     */
    @Excel(name = "创建者")
    private String creator;

    /**
     * 创建者ID
     */
    @Excel(name = "创建者ID")
    private String creatorId;

    /**
     * 题名
     */
    @Excel(name = "题名")
    private String title;

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;

    /**
     * 档案id
     */
    private String filesId;

    /**
     * 流程实例信息
     */
    private String processInstance;

    /**
     * 任务 0  不同意  1 同意  2 待审批 3 取消审批
     */
    private String task;


    /**
     * 任务id
     */
    private String taskId;

    /**
     * 关联表名
     */
    private String subTableName;

    /**
     * 审批类型 1 密级  2 保管期限
     */
    private String approveType;

    public String getApproveType() {
        return approveType;
    }

    public void setApproveType(String approveType) {
        this.approveType = approveType;
    }

    public String getTableName() {
        return tableName;
    }

    public String getTaskId() {
        return taskId;
    }

    public void setTaskId(String taskId) {
        this.taskId = taskId;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getCategoryId() {
        return categoryId;
    }

    public void setCategoryId(String categoryId) {
        this.categoryId = categoryId;
    }

    public String getCategoryName() {
        return categoryName;
    }

    public void setCategoryName(String categoryName) {
        this.categoryName = categoryName;
    }

    public String getMenuId() {
        return menuId;
    }

    public void setMenuId(String menuId) {
        this.menuId = menuId;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getMjChange() {
        return mjChange;
    }

    public void setMjChange(String mjChange) {
        this.mjChange = mjChange;
    }

    public String getCreator() {
        return creator;
    }

    public void setCreator(String creator) {
        this.creator = creator;
    }

    public String getCreatorId() {
        return creatorId;
    }

    public void setCreatorId(String creatorId) {
        this.creatorId = creatorId;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public String getFilesId() {
        return filesId;
    }

    public void setFilesId(String filesId) {
        this.filesId = filesId;
    }

    public String getProcessInstance() {
        return processInstance;
    }

    public void setProcessInstance(String processInstance) {
        this.processInstance = processInstance;
    }

    public String getTask() {
        return task;
    }

    public void setTask(String task) {
        this.task = task;
    }

    public String getSubTableName() {
        return subTableName;
    }

    public void setSubTableName(String subTableName) {
        this.subTableName = subTableName;
    }

    public String getMjType() {
        return mjType;
    }

    public void setMjType(String mjType) {
        this.mjType = mjType;
    }


    @Override
    public String toString() {
        return new ToStringBuilder(this)
                .append("tableName", tableName)
                .append("ID", id)
                .append("categoryId", categoryId)
                .append("categoryName", categoryName)
                .append("menuId", menuId)
                .append("type", type)
                .append("state", state)
                .append("mjChange", mjChange)
                .append("mjType", mjType)
                .append("creator", creator)
                .append("creatorId", creatorId)
                .append("title", title)
                .append("createTime", createTime)
                .append("filesId", filesId)
                .append("processInstance", processInstance)
                .append("task", task)
                .append("taskId", taskId)
                .append("subTableName", subTableName)
                .toString();
    }

    public Map<String, Object> toProcessMap() {
        Map<String, Object> map = new HashMap<>();

        // 使用反射获取实体类的字段信息
        Class<?> clazz = this.getClass();
        Field[] fields = clazz.getDeclaredFields();

        try {
            // 遍历所有字段，获取字段名和字段值，并存储到 Map 中
            for (Field field : fields) {
                if (field.getType().isAssignableFrom(Date.class)) {
                    continue;
                }
                field.setAccessible(true); // 设置字段可访问，即使是私有字段也可以获取值
                String fieldName = field.getName();
                Object fieldValue = field.get(this); // 获取字段的值
                map.put(fieldName, fieldValue);
            }
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

        return map;
    }
}
